package com.wanli.agent.performance.model;

import com.wanli.agent.appconst.MethodType;
import com.wanli.agent.appconst.URLConst;
import com.wanli.agent.base.DataCallBack;
import com.wanli.agent.bean.StatisticsBean;
import com.wanli.agent.retorfit_manager.ResponseObserver;
import com.wanli.agent.retorfit_manager.RetrofitHelper;
import com.wanli.agent.utils.ToastUtil;

import java.util.HashMap;
import java.util.Map;

public class PerformanceModelImpl implements IPerformanceModel {

    @Override
    public void requestStatistics(DataCallBack<StatisticsBean> callBack) {
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.STATISTICS, null, new ResponseObserver<StatisticsBean>() {
            @Override
            public void onSuccessful(StatisticsBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(StatisticsBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestLineStatistics(String cycleType, String param, DataCallBack<StatisticsBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("cycleType", cycleType == null ? "" : cycleType);
        params.put("param", param);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.getLineStatistics, params, new ResponseObserver<StatisticsBean>() {
            @Override
            public void onSuccessful(StatisticsBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(StatisticsBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

}
